#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define ull unsigned long long
const int mod=998244353;
int n,a[1005];
bitset <1005> rgs[2][1005],adans;
struct Node
{
    bitset <1005> ok;
    int val;
};
unordered_map <ull,int> ma;
bitset <1005> tmp;
Node nxt(Node u,int ad)
{
    tmp=u.ok,u.ok.reset();
    for(int i=0;i<=n;i++) if(tmp[i]) u.ok|=rgs[ad][i];
    return u;
}
ull Hsh(Node &u)
{
    ull h=0;
    for(int i=0;i<=n;i++) h*=131,h+=u.ok[i];
    return h;
}
int ans=0;
void solve()
{
    // cin>>n;
    string str;
    cin>>str;
    n=str.size();
    int vali=1;
    for(int i=0;i+1<n;i++) if(str[i]==str[i+1]) vali=0;
    if(vali)
    {
        // cerr<<"...\n";
        if(str[0]=='A') n--;
        cout<<n/2+1<<"\n";
        return;
    }
    // if(n>0)
    // {
    //     int x=1,ans=1;
    //     for(int i=2;i<=n;i+=2) x=4LL*x%mod,ans=(ans+x)%mod;
    //     cout<<"... "<<ans<<"\n";
    //     return;
    // }
    for(int i=1;i<=n;i++) a[i]=(str[i-1]=='A'?0:1);
    for(int i=0;i<n;i++) rgs[a[i+1]][i][i+1]=1;
    for(int l=1;l<=n;l++)
    {
        int bad=1;
        for(int r=l+1;r<=n;r+=2)
        {
            if(a[l]==1||a[r]==0||!bad) 
            {
                rgs[a[r+1]][l-1][r+1]=1;
                if(r==n) adans[l-1]=1;
            }
            if(a[r]==0&&a[r+1]==1) bad=0;
        }
    }
    adans[n]=1;
    vector <Node> vec;
    Node _;
    _.val=1,_.ok.reset(),_.ok[0]=1;
    vec.pb(_);
    if(adans[0]) ans++;
    
    for(int i=1;i<=n;i++)
    {
        vector <Node> vec2;
        ma.clear();
        for(int j=0;j<vec.size();j++) 
        {
            Node t=nxt(vec[j],0);
            ull ha=Hsh(t);
            if(ma.find(ha)==ma.end()) ma[ha]=vec2.size(),vec2.pb(t);
            else 
            {
                int p=ma[ha];
                vec2[p].val=(vec2[p].val+t.val)%mod;
            }

            t=nxt(vec[j],1);
            ha=Hsh(t);
            if(ma.find(ha)==ma.end()) ma[ha]=vec2.size(),vec2.pb(t);
            else 
            {
                int p=ma[ha];
                vec2[p].val=(vec2[p].val+t.val)%mod;
            }
        }
        swap(vec,vec2);
        int del=0;
        for(int j=0;j<vec.size();j++) if((vec[j].ok&adans).count()) ans=(ans+vec[j].val)%mod;//,del=(del+vec[j].val)%mod;
        // cout<<del<<"\n";
        // cerr<<vec.size()<<"\n";
    }
    cout<<ans<<"\n";
    /*
    int tot=0;
    for(int mask=0;mask<(1<<n);mask++)
    {
        for(int i=1;i<=n;i++)
        {
            if(mask&(1<<(i-1))) a[n-i+1]=1;
            else a[n-i+1]=0;
        }
        memset(dp,0,sizeof(dp));
        for(int len=2;len<=n;len++) for(int l=1;l+len-1<=n;l++)
        {
            int r=l+len-1;
            for(int x=l;x<=r;x++) for(int y=x+1;y<=r;y++)
            {
                if(a[x]==0&&a[y]==1) continue;
                int ok=1;
                if(x>l&&!dp[l][x-1]) ok=0;
                if(x+1<=y-1&&!dp[x+1][y-1]) ok=0;
                if(y+1<=r&&!dp[y+1][r]) ok=0;
                if(ok) dp[l][r]=1;
            }
        }
        if(!dp[1][n])
        {
            for(int i=1;i<=n;i++) cout<<(a[i]==0?"A":"B");
            cout<<"\n";
            tot++;
        }
    }
    cout<<tot<<"\n";
    */
}
signed main()
{
    freopen("song.in","r",stdin);
    freopen("song.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _=1;
    // cin>>_;
    while(_--) solve();
    return 0;
}

/*
g++ -o song song.cpp -O2 -std=c++17 -Wall -Wextra -Wconversion -Wshadow

g++ -o song song.cpp -O2 -std=c++14 -Wall -Wextra -Wconversion -Wshadow -fsanitize=undefined -fsanitize=address -D_GLIBCXX_DEBUG -g 
*/